#pragma once

#include <memory>

#include "IHttpContext.h"

namespace Poco
{
	class Event;

	namespace Net
	{
		class HTTPServerRequest;
		class HTTPServerResponse;
	};
};

namespace MiniHttpServer
{
	ref class HttpRequest;
	ref class HttpResponse;

	class HttpContextHandler
	{
	public:
		HttpContextHandler(Poco::Event& ev);
		virtual ~HttpContextHandler();

	private:
		Poco::Event& m_event;
	};

	ref class HttpContext : public IHttpContext, public System::IDisposable
	{
	public:
		HttpContext(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response, std::shared_ptr<HttpContextHandler> const& pContext);
		virtual ~HttpContext();
		!HttpContext();

		virtual property IHttpRequest^ Request { IHttpRequest^ get() override { return m_request; }; };
		virtual property IHttpResponse^ Response { IHttpResponse^ get() override { return m_response; }; };
		// manually finalize the request, the context, request and response become invalid when this is called
		virtual void Close() override;
	private:
		IHttpRequest^ m_request;
		IHttpResponse^ m_response;
		std::shared_ptr<HttpContextHandler>* m_ppContextHandler;
	};
};